from django.shortcuts import render
from django.views import View
from QQLoginTool.QQtool import OAuthQQ
from django.conf import settings
from django import http

from meiduo_mall.utils.response_code import RETCODE
# Create your views here.


class QQAuthURLView(View):
    """qq登录视图"""
    def get(self, request):
        # 获取参数
        next_url = request.GET.get('next')

        # 创建QQ登录对象
        oauth = OAuthQQ(
            client_id=settings.QQ_CLIENT_ID,
            client_secret=settings.QQ_CLIENT_SECRET,
            redirect_uri=settings.QQ_REDIRECT_URI,
            state=next_url
        )

        # 获取扫码页面链接
        login_url = oauth.get_qq_url()

        # 返回数据
        return http.JsonResponse({'code': RETCODE.OK, 'errmsg': 'OK', 'login_url': login_url})

